//
//  NWalletDetailHeaderView.m
//  News
//
//  Created by zhangtao on 2018/10/10.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "NWalletDetailHeaderView.h"

@implementation NWalletDetailHeaderView
{
    UIButton *selectBtn;
    UIView *bottomView;
}

-(instancetype)initWithFrame:(CGRect)frame items:(NSArray *)items{
    if (self = [super initWithFrame:frame]) {
        
        for (int i = 0; i<items.count; i++) {
            CGSize size = [ACEPublicTool textViewWeightWithTextFont:BASE_FONT andText:items[i] andSize:CGSizeMake(200, frame.size.height-10)];
            UIButton *btn = [[UIButton alloc]init];
            [btn setTag:i];
            [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
            [btn setTitle:items[i] forState:UIControlStateNormal];
            [btn sizeToFit];
            btn.frame  = CGRectMake(frame.size.width/(items.count+1)*(i+1)-size.width/2, 2,size.width, frame.size.height-8);

            if (i == 0) {
                btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

                selectBtn = btn;
                
                bottomView = [[UIView alloc]initWithFrame:CGRectMake(btn.frame.origin.x, frame.size.height-3, btn.frame.size.width, 2)];
                bottomView.backgroundColor = MAIN_COLOR;
                [self addSubview:bottomView];
                
            }else{
                [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];

//                btn.frame  = CGRectMake(frame.size.width/items.count+50, 0, size.width, frame.size.height-10);
                btn.titleLabel.font = [UIFont systemFontOfSize:15];
            }
        }
        
        UILabel *bottomLab = [[UILabel alloc]initWithFrame:CGRectMake(0, frame.size.height-1, ACEWidth, 1)];
        bottomLab.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self addSubview:bottomLab];
    }
    return self;
}

-(void)click:(UIButton *)btn{
    btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    bottomView.frame = CGRectMake(btn.frame.origin.x, bottomView.frame.origin.y, btn.frame.size.width, 2);
    selectBtn.titleLabel.font = BASE_FONT;
    [selectBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    selectBtn = nil;
    selectBtn = btn;
    
    if (self.WalletDetailViewCallBack) {
        self.WalletDetailViewCallBack(btn.tag);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
